# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=rxspencer
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=alpha3.8.g7
pkgrel=1
pkgdesc="Henry Spencer's BSD regular expression library modified to allow building as a shared library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://garyhouston.github.io/regex/"
options=('strip' 'staticlibs')
license=('custom')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/garyhouston/${_realname}/archive/${pkgver}.tar.gz)
noextract=(${_realname}-${pkgver}.tar.gz)
sha256sums=('f6fb78dbd47de0c1509463474d32a109ac9bec180208f3943228c6731fe964f3')

prepare() {
  tar --exclude=ltmain.sh -zxf ${_realname}-${pkgver}.tar.gz

  cd "${srcdir}"/${_realname}-${pkgver}
  autoreconf -f -i
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  mkdir ${pkgdir}/${MINGW_PREFIX}/bin
  mv ${pkgdir}${MINGW_PREFIX}/lib/librxspencer-0.dll ${pkgdir}/${MINGW_PREFIX}/bin

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYRIGHT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYRIGHT"
}
